clear
set more      off
set varabbrev off
set gr        off
set linesize 255

/* INPUTS */

local in_aku 		"/home/projects/cedsei/data/AKUsearch"
local in_iaf 		"/data2/cedsei/data2/IAF_cleaned_v4"


/* OUTPUTS */

local out_search 	"/data2/cedsei/data2/search_data"
local out_ui 		"/data2/cedsei/data2/search_ui"

*cd "/data2/cedsei/data2"

********************************************************************************

clear 
use `in_aku'
rename persid lopnr 
drop date ref_week 
gen date = ym(year,month)
format date %tm 
drop year month 
order lopnr date 
sort lopnr date 

foreach var of varlist search_afcoach search_afself search_databa search_recruit search_direct search_postads search_readads search_friends search_interview search_int {
	replace `var' = 0 if mi(`var')	
}

keep lopnr date search_int search_afcoach search_afself search_databa search_recruit search_direct search_postads search_readads search_friends search_interview search_int
gen search_ext = search_int>0
replace date = date  - 1
save	`out_search', replace

clear 
use `in_iaf'
merge m:1 lopnr date using `out_search'
tab date _merge
drop if _merge==2
drop _merge

save `out_ui', replace 
